package com.ruoyi.web.controller.evaluation;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.evaluation.Complaint;
import com.ruoyi.system.domain.evaluation.ComplaintandStore;
import com.ruoyi.system.domain.evaluation.Location;
import com.ruoyi.system.domain.evaluation.StoreLocation;
import com.ruoyi.system.service.evaluationService.ComplaintService;
import com.ruoyi.system.service.evaluationService.LocationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/evaluation")
public class ComplaintController extends BaseController {
    String prefix = "evaluation/";
    @Autowired
    private ComplaintService complaintService;
    @Autowired
    private LocationService locationService;
    /**
     * 跳转反馈页面
     * @return
     */
    @RequiresPermissions("evaluation:complaint:view")
    @GetMapping("/complaint")
    public String listEvaluation(ModelMap map){
        List<Location> locations =locationService.selectLocation();
        map.put("locations",locations);
        return prefix+"complaint";
    }

    @RequiresPermissions("evaluation:complaint:view")
    @PostMapping("/complaintList")
    @ResponseBody
    public TableDataInfo list(String storeName,String location_id){
        startPage();
        System.out.println(location_id);
        System.out.println(storeName);
        List<ComplaintandStore> list = complaintService.selectComplaintList(storeName,location_id);
        return  getDataTable(list);
    }

    /**
     * 导出商品评价数据
     * @param ids
     * @return
     */
    @PostMapping("/exportComplaint")
    @ResponseBody
    public AjaxResult export(String ids){
        System.out.println("ids================"+ids);
        //加入所选择的参数，可以导出全部或者选定的部分
        //List<StoreLocation> list = storeService.selectStoreByListId(ids);
        List<ComplaintandStore> list = complaintService.selectComplaintByIds(ids);
        ExcelUtil<ComplaintandStore> util = new ExcelUtil<ComplaintandStore>(ComplaintandStore.class);
        return util.exportExcel(list,"饮食投诉数据表");
    }
    /**
     * 删除评价
     * @param ids
     * @return
     */
    @RequiresPermissions("evaluation:complaint:view")
    @PostMapping("/removeComplaint")
    @ResponseBody
    public AjaxResult removeComplaint(String ids)
    {
        try
        {
            //根据删除story的数据
            int num = complaintService.deleteComplaint(ids);
            if (num>0){
                return success();
            }else{
                return error("删除失败哦！！");
            }
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }


}
